import { HashMap } from "../../api/struct/HashMap";
import { CDEquipmentLevel } from "../excel/CDEquipmentLevel";

/**
 * 扩展-部位强化等级
 */
export abstract class CEEquipmentLevel {

    public static playerPartMaxLevelMap = new HashMap<number, number>();

    /**初始化 */
    public static init(): void {
        const vs = CDEquipmentLevel.datas.getValues();
        for (let i = 0, len = vs.length; i < len; i++) {
            // 老的装备强化表，还区分装备品质。
            // 现在是把装备等级当玩家等级处理，品质不需要了。只取品质1的数据
            if (vs[i].color !== 1) {
                continue;
            }
            this.playerPartMaxLevelMap.put(vs[i].level, vs[i].maxStrengthenLevel);
        }
    }

    /**
     * 根据玩家等级获取部位最大强化等级。
     * 所有部位最大强化等级都一样。
     * @param playerLevel 玩家等级
     * @returns 最大强化等级
     */
    public static getPlayerPartMaxLevel(playerLevel: number): number {
        const playerLevels = this.playerPartMaxLevelMap.getKeys();
        const defaultLevel = 1;
        if (playerLevels.length == 0) {
            return defaultLevel; //如果没有等级区级，默认最大强化到1级
        }
        let startLevel = playerLevels[0];
        for (let level of playerLevels) {
            if (playerLevel >= level) {
                startLevel = level;
            } else {
                break;
            }
        }
        return this.playerPartMaxLevelMap.get(startLevel) || defaultLevel;
    }
}
